<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>模块列表</title>
<script src="../../js/jquery-3.1.1.min.js" charset="utf-8" ></script>
<script src="../../js/Verification.js"></script>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="stylesheet" href="../../layui/css/layui.css" media="all">
<!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
<link rel="stylesheet" href="../../layui/css/treeselect.css">
</head>
<style>
#typeName{
    padding: 5px 0;
    min-width: 100%;
    border: 1px solid #d2d2d2;
    max-height: 300px;
    overflow-y: auto;
    background-color: #fff;
    border-radius: 2px;
    box-shadow: 0 2px 4px rgba(0,0,0,.12);
    box-sizing: border-box;
}
</style>
<body>
	<div class="demoTable">
		模块名字：
		<div class="layui-inline">
			<input class="layui-input" name="modName" id="modname"
				autocomplete="off" size="34">
		</div>
		
		<button class="layui-btn" data-type="reload">搜索</button>
		<button class="layui-btn layui-btn-primary" onclick="add();">增加</button>
	</div>
	<table class="layui-table"
		lay-data="{ url:'../../drugModule/findAll.action', page:true, id:'idTest'}"
		lay-filter="demo">
		<thead>
			<tr>
				<th lay-data="{field:'modulePName', width:100, align:'center'}">上级模块</th>
				<th lay-data="{field:'url', width:100, align:'center'}">模块URL</th>
				<th lay-data="{field:'modName', width:100, align:'center'}">模块名称</th>
				<th lay-data="{field:'modDesc', width:120, align:'center'}">模块说明</th>
				<th lay-data="{field:'isvas', width:120, align:'center'}">是否有效</th>
				<th lay-data="{field:'optimes', width:120, align:'center'}">操作时间</th>
				<th lay-data="{field:'oper', width:120, align:'center'}">操作人</th>
				<th lay-data="{fixed: 'right', width:178, align:'center', toolbar: '#barDemo'}">操作</th>
			</tr>
		</thead>
	</table>

	<script type="text/html" id="barDemo">
{{# if(d.moduleCode=='' || d.moduleCode==null){ }}
		<a class="layui-btn layui-btn-xs" lay-event="edit">修改</a>
		<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
{{# } else{}}
<a class="layui-btn layui-btn-disabled layui-btn-xs" >修改</a>
		<a class="layui-btn layui-btn-disabled layui-btn-xs" >删除</a>
{{# } }}
</script>
	<script src="../../layui/layui.js" charset="utf-8"></script>
<script type="text/javascript">
layui.config({
	  base: '../../layui/lay/modules/'
	}).extend({ //设定模块别名
		treeselect: 'treeselect'
	});
</script>
	<script>
	
		layui.use('table', function() {
			var table = layui.table;
			//监听表格复选框选择
			table.on('checkbox(demo)', function(obj) {
				console.log(obj)
			});
			//监听工具条
			table.on('tool(demo)', function(obj) {
	
				
				var data = obj.data;
				if (obj.event === 'del') {
					layer.confirm('真的删除么', function(index) {
						layer.close(index);
						var id = data.id;
						var url = "../../drugModule/delete.action";
						var datas = {
							'modId' : id
						};
						$.ajax({
							asyn : true,
							type : "POST",
							url : url,
							data : datas,
							success : function(msg) {
								if (msg.state == 0) {
									layer.msg(msg.msg);
									table.reload('idTest');
								} else {
									layer.msg(msg.msg, {
										  icon: 1,
										  time: 1000 //1秒关闭（如果不配置，默认是3秒）
										}, function(){
										  table.reload('idTest');
									});
								}
							},
							error : function(fh) {
								layer.msg(msg.msg);
							}
						},"json");
					});
				} else if (obj.event === 'edit') {
					var pid = "main";
					layer.confirm('<table id="tab"><tr><td>'+
							'<div class="layui-input-inline"></div></td></tr>'+
							'<tr><td>上级模块:</td><td><input type="text" id="treeselecttests" placeholder="不选为根模块" autocomplete="off" class="layui-input" value='+data.ehyModId+'></td></tr>'+
							'<tr><td>模块URL:</td><td><input type="text" name="url" class="layui-input" maxlength="100" id="url" value='+data.url+'></td></tr>'+
							'<tr><td>模块名称:</td><td><input type="text" name="modName" class="layui-input" maxlength="20" id="modName" value='+data.modName+'></td></tr>'+
							'<tr><td>模块说明:</td><td><input type="text" name="modDesc" class="layui-input" maxlength="20" id="modDesc" value='+data.modDesc+'></td></tr>'+
							'<tr><td>是否有效:</td><td>'+
							'<select name="isva" id="isva" value="'+data.isva+'">'+
							'<option value="0">是</option>'+
							'<option value="1">否</option>'+
							'</select></td></tr>'+
							'<tr><td>操作人:</td>'+
							'<td><input type=text class="layui-input" maxlength="20" name="moduleOper" id="oper" value='+data.oper+'></td></tr>'+
							'</table>', function(index) {
						var id = data.modId;
						var url = "../../drugModule/saveOrUpdate.action";
						var datas = {
							'modId' : id,
							'ehyModId' : pid,
							'url' : $("#url").val(),
							'modName' : $("#modName").val(),
							'modCode' : $("#modCode").val(),
							'modDesc' : $("#modDesc").val(),
							'isva' : $("#isva").val(),
							'oper' : $("#oper").val(),
							'sort' : $("#sort").val()
						};
						$.ajax({
							asyn:true,
							type:"POST",
							url:url,
							data:datas,
							success:function(msg){
								if(msg.state == 0){
									layer.msg(msg.msg, {
										  icon: 1,
										  time: 1000 //1秒关闭（如果不配置，默认是3秒）
										}, function(){
										  table.reload('idTest');
										  location.reload();
									});
									
								}else{
									layer.msg(msg.msg, {
										  icon: 1,
										  time: 1000 //1秒关闭（如果不配置，默认是3秒）
										}, function(){
											location.reload();
									});
								}
							},
							error:function(fh){
								layer.msg("修改失败", {
									  icon: 1,
									  time: 1000 //1秒关闭（如果不配置，默认是3秒）
									}, function(){
										
								});
							}
						},"json");
					
					});
				}
				layui.use('treeselect', function () {
		            treeselect = layui.treeselect;
		            treeselect.render(
		            {
		                elem: "#treeselecttests",
		                data: "../../drugModule/findAllByGroup.action",
		                method: "GET",
		                click: function(node){
		                	pid = node.id;
		                } 
		            });
		        });
			});
		
			var $ = layui.$, active = {
				reload : function() {
					//执行重载
					table.reload('idTest', {
						
						where : {
							'modName' : $("#modname").val()
						},
						page : {
							curr : 1
						}
					});
				}
			};
			
			$('.demoTable .layui-btn').on('click', function() {
				var type = $(this).data('type');
				active[type] ? active[type].call(this) : '';
			});
			
		});
		var num;
		function add(){
			var modId = "main";
			num = 0;
			layer.confirm('<form id="ByName">'+
					'<table id="tab">'+
					'<tr><td><div class="layui-input-inline"></div></td></tr>'+
					'<tr><td>上级模块:</td>'+
					'<td><input type="text" id="treeselecttest" placeholder="不选为根模块" autocomplete="off" class="layui-input"></td></tr>'+
					'<tr><td>模块URL:</td>'+
					'<td><input type="text" class="layui-input" maxlength="20" name="url" id="url" ></td></tr>'+
					'<tr><td>模块名称:</td><td><input class="layui-input" maxlength="20" type=text  name="modName" id="modName" ></td></tr>'+
					'<tr><td>模块说明:</td><td><input class="layui-input" maxlength="20" type=text  name="modDesc" id="modDesc" ></td></tr>'+
					'<tr><td>模块编码:</td><td><input type="text" name="modCode" placeholder="请输入编码 非店铺模块不填" class="layui-input" maxlength="100" id="moduleCode" ></td></tr>'+
					'<tr><td>是否有效:</td><td>'+
					'<select name="isva" id="isva" lay-verify="required" lay-search="">'+
					'<option value="0">是</option>'+
					'<option value="1">否</option></select></td></tr>'+
					'<tr><td>操作人:</td><td><input class="layui-input" maxlength="20" type=text  name="oper" id="oper" ></td></tr>'+
					'</table></form>', function(index) {
				addOK(modId)
			});
			
			layui.use('treeselect', function () {
	            treeselect = layui.treeselect;
	            treeselect.render(
	            {
	                elem: "#treeselecttest",
	                data: "../../drugModule/findAllByGroup.action",
	                method: "GET",
	                click: function(node){
	                	
	                	modId = node.id;
	                	
	                } 
	            });
	        });
		}
		
		layui.use('laydate', function(){
			  var laydate = layui.laydate;
			  //日期范围
			  laydate.render({
			    elem: '#test6'
			    ,range: true
			  });
		});

		//确认采购
		function addOK(modId){
			var url = "../../drugModule/saveOrUpdate.action";
			var datas = $.param({"ehyModId":modId}) + "&" + $("#ByName").serialize();
			$.ajax({
				asyn:true,
				type:"POST",
				url:url,
				data:datas,
				success:function(msg){
					if(msg.state == 0){
						layer.msg(msg.msg, {
							  icon: 1,
							  time: 1000 //1秒关闭（如果不配置，默认是3秒）
							}, function(){
								location.reload();
						});
						
					}else{
						layer.msg(msg.msg, {
							  icon: 1,
							  time: 1000 //1秒关闭（如果不配置，默认是3秒）
							}, function(){
								location.reload();
						});
					}
				},
				error:function(fh){
					layer.msg("增加失败");
				}
			},"json");
			
		};
	  
	  //鼠标放上去显示颜色
	  function showColor(){
	  	
		$("#tab tr:gt(0)").hover(
			function(){$(this).addClass("hover_bg")},
			function(){$(this).removeClass("hover_bg")}
		);
	  }
	  
	  
	  //删除一行
	  
	  function deleteRows(obj){
	  	
	  	var tr = obj.parentNode;
		var row = tr.rowIndex;
	  	$("#tab tr:eq("+row+")").remove();
	  }
	</script>

</body>
</html>